package com.example.tuike.controller;
import com.example.tuike.entity.Platforms;
import com.example.tuike.service.PlatformsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/*** @Author supersaiya
 * @Description TODO

 * @Date 2025/2/2 21:27

 * @Version 1.0*/


import java.util.List;

@RestController
@RequestMapping("/api/platforms")
public class PlatformsController {

    @Autowired
    private PlatformsService platformsService;

    @GetMapping
    public ResponseEntity<List<Platforms>> getAllPlatforms() {
        List<Platforms> platforms = platformsService.getAllPlatforms();
        return ResponseEntity.ok(platforms);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Platforms> getPlatformById(@PathVariable Integer id) {
        Platforms platform = platformsService.getPlatformById(id);
        if (platform == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(platform);
    }

    @PostMapping
    public ResponseEntity<Platforms> createPlatform(@RequestBody Platforms platform) {
        Platforms createdPlatform = platformsService.createPlatform(platform);
        return ResponseEntity.ok(createdPlatform);
    }

    @PutMapping("/{id}")
    public ResponseEntity<Platforms> updatePlatform(@PathVariable Integer id, @RequestBody Platforms platform) {
        platform.setPlatformId(id);
        Platforms updatedPlatform = platformsService.updatePlatform(platform);
        return ResponseEntity.ok(updatedPlatform);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deletePlatform(@PathVariable Integer id) {
        platformsService.deletePlatform(id);
        return ResponseEntity.noContent().build();
    }
}